package com.taobao.analyse.map;

import java.io.IOException;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

import com.taobao.analyse.constants.SplitConstants;

public class AuctionCategoryTitleMapper extends MapReduceBase implements
		Mapper<Writable, Text, LongWritable, Text> {

	@Override
	public void map(Writable key, Text value,
			OutputCollector<LongWritable, Text> output, Reporter reporter)
			throws IOException {
		String line = value.toString();
		if (StringUtils.isEmpty(line)) {
			return;
		}
		
		String[] datas = StringUtils.splitPreserveAllTokens(line, SplitConstants.ITEM_REGX);
		
		if(datas.length<14){
			return;
		}
		
		String cid = datas[0];
		String pid = datas[1];
		String name = datas[12];
		
		if(!pid.equals("0")){
			return;
		}
		
		output.collect(new LongWritable(Long.parseLong(cid)), new Text("categoryName"+SplitConstants.SPLIT_AT+name));
	}

}
